package Game.Spawners;

import java.util.Random;

import Game.GameHelper;
import Game.Level;
import Game.MapBlock.EMapBlockType;
import GameMath.GPoint;
import GameMath.GSize;

/** Spawn player class
 * @author Aikidos
 */
public class SpawnPlayer extends SpawnerBase {

	@Override
	public void spawn(Level level) {
		// Get random
		Random rnd = GameHelper.getRandom();
		
		// Get map size
		GSize mapSize = level.getMap().getSize();
		
		// Spawn
		GPoint spawnPos = new GPoint(rnd.nextInt(mapSize.width),
				rnd.nextInt(mapSize.height));
		while (level.getMap().getBlocks()[spawnPos.x][spawnPos.y].Type != EMapBlockType.Floor)
			spawnPos = new GPoint(rnd.nextInt(mapSize.width), rnd.nextInt(mapSize.height));

		level.getObjectManager().getPlayer().Position = level.getObjectManager().coordToObjectPos(spawnPos);
		
		// Initialize self light
		level.getObjectManager().getPlayer().initSelfLight();
		
		// Set camera position to player position
		level.getObjectManager().getCamera().lookAt(level.getObjectManager().getPlayer());
		
		// Update fog of war
		level.updateOpenedMap();
	}

	
	
}
